package com.system.util.drools;


import java.text.SimpleDateFormat;
import java.util.Date;

import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;

import com.system.util.PageData;


/**
 @Function
 @Author 于泓磊
 @Date   2017年12月18日
*/
public class DroolsFactory {

	public static void excuteDrools(PageData pd){
   
        // 构建KieServices
        KieServices ks = KieServices.Factory.get();
        KieContainer kieContainer = ks.getKieClasspathContainer();
        KieSession kSession = kieContainer.newKieSession("allrules");
       
        kSession.insert(pd);
        int count = kSession.fireAllRules();
        System.out.println("执行了" + count + "条规则!");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        String format = sdf.format(date);
        pd.put("date", format);
    }
	
	public static void excuteCoupon(PageData pd){
		   
        // 构建KieServices
        KieServices ks = KieServices.Factory.get();
        KieContainer kieContainer = ks.getKieClasspathContainer();
        KieSession kSession = kieContainer.newKieSession("allcouponrules");
       
        kSession.insert(pd);
        int count = kSession.fireAllRules();
        System.out.println("执行了" + count + "条规则!");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        String format = sdf.format(date);
        pd.put("date", format);
    }
}
